package com.syxp.pda.action.report;

import java.util.List;

import javax.annotation.Resource;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.syxp.pda.core.util.TimeFormatUtil;
import com.syxp.pda.core.web.action.BaseAction;
import com.syxp.pda.entity.base.Profess;
import com.syxp.pda.entity.report.CheckLogReport;
import com.syxp.pda.service.report.CheckLogReportService;

public class LogAction extends BaseAction {
	@Resource
	private CheckLogReportService checkLogReportService;

	public CheckLogReportService getCheckLogReportService() {
		return checkLogReportService;
	}

	public void setCheckLogReportService(CheckLogReportService checkLogReportService) {
		this.checkLogReportService = checkLogReportService;
	}
	private CheckLogReport checkLogReport;

	public CheckLogReport getCheckLogReport() {
		return checkLogReport;
	}

	public void setCheckLogReport(CheckLogReport checkLogReport) {
		this.checkLogReport = checkLogReport;
	}
	
	public String load(){
		try{
			System.out.println("dsdsd");
			List<CheckLogReport> all=checkLogReportService.getDao().getAll();
			JsonArray jarray = new JsonArray() ;
			for(CheckLogReport checkLogReport : all) {
				JsonObject jobj = new JsonObject() ;
				jobj.addProperty("id", checkLogReport.getCheckLogReportID()) ;
				jobj.addProperty("name", checkLogReport.getLogReportName()) ;
				jobj.addProperty("remark", checkLogReport.getRemarks()) ;
				jobj.addProperty("number", checkLogReport.getLogReportNo()) ;
				jobj.addProperty("status", checkLogReport.getLogReportStatus()) ;
				jobj.addProperty("primaryKey", checkLogReport.getLogReportKey()) ;
				jobj.addProperty("logname", checkLogReport.getLogReportName()) ;
				jobj.addProperty("datetime", TimeFormatUtil.formatDateF(checkLogReport.getLogReportDate())) ;
				jarray.add(jobj) ;
			}
			this.jsonString = gson.toJson(jarray) ;
			System.out.println(jsonString) ;
			return SUCCESS ;
		}catch(Exception e){
			e.printStackTrace();
			return SUCCESS;
		}
	}
	public String save(){
		try{
			checkLogReportService.addService(checkLogReport);
			JsonObject jobj=new JsonObject();
			jobj.addProperty("success", true) ;
			this.jsonString=super.gson.toJson(jobj) ;
		}catch(Exception e){
			e.printStackTrace();
		}
		return SUCCESS;
	}
}
